package com.community.service.impl;

import com.community.common.utils.DateUtils;
import com.community.common.utils.SecurityUtils;
import com.community.domain.OrderEntity;
import com.community.mapper.OrderMapper;
import com.community.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper OrderMapper;


    @Override
    public List<OrderEntity> selectOrder(OrderEntity OrderEntity) {
        return OrderMapper.selectOrder(OrderEntity);
    }

    @Override
    public Integer addOrder(OrderEntity OrderEntity) {
        OrderEntity.setStatus("0");
        OrderEntity.setCreateTime(DateUtils.getNowDate());
        OrderEntity.setOrdererId(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
        OrderEntity.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUsername()));
        return OrderMapper.addOrder(OrderEntity);
    }

    @Override
    public Integer editOrder(OrderEntity OrderEntity) {
        OrderEntity.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUsername()));
        return OrderMapper.editOrder(OrderEntity);
    }

    @Override
    public Integer deleteOrder(int id) {
        return OrderMapper.deleteOrder(id);
    }

    @Override
    public Integer receiveOrder(OrderEntity orderEntity) {
        orderEntity.setStatus("1");
        orderEntity.setTakerId(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
        orderEntity.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUsername()));
        return OrderMapper.receiveOrder(orderEntity);
    }

    @Override
    public OrderEntity selectOrderType(OrderEntity order) {
        return OrderMapper.selectOrderType(order);

    }
    @Override
    public int countnumber() {
        return OrderMapper.countnumber();
    }
}